<script setup lang="ts">
	import { onLoad } from '@dcloudio/uni-app'
	import { computed, onBeforeMount, ref } from 'vue';
	import type { IUserInfo } from '@/simba/types/user.d';
	import type { IConserve } from '@/simba/types/conserve.d';
	// let userId = ref()
	import { useConserve } from '@/simba/hooks/conserve';
	const { getUserInfo, addConserve } = useConserve()
	
	import sheep from '@/sheep';
	const user = computed(() => sheep.$store('user').userInfo);
	
	const userInfo = ref<IUserInfo>(
	{
		nickname: '',
		avatar: '',
		mobile: '',
		level: {},
		sex: 0
	}
	)
	
	// 获得用户信息
	const formData = ref<IConserve>({
		// id: null,
		userid: 0,
		conserveUserid: 0,
		// nickname: '',
		// mobile:'',
		// avatar:'',
		statusApprova: 0,
		remark: '',
		// refuseReason: ''
	})
		
	onLoad(async (options?: AnyObject)=>{
		formData.value.userid = options.uid //出示二维码的用户
		userInfo.value = await getUserInfo(options.uid);
		// console.log('userInfo', userInfo.value)
	})

	function onAddConserveHandler(){
		formData.value.conserveUserid = user.value.id  //扫二维码的人，发起申请者
		addConserve(formData.value)
	}
</script>

<template>
	<siScanQrCode :userInfo="userInfo">
		<template>
			<view class="">
				<view class="remark">
					<span style="">备注</span>
					<up-textarea v-model="formData.remark" placeholder="请输入内容" count ></up-textarea>
				</view>
				<up-button type="primary" text="申请添加养护人" @tap="onAddConserveHandler"></up-button>
			</view>
		</template>
	</siScanQrCode>
	<!-- <up-divider></up-divider> -->
		<!-- <view class="user">
			<up-image v-if="userInfo.avatar" :show-loading="true" :src="userInfo.avatar" radius= 10 width="80px" height="80px"></up-image>
			<up-image v-else :show-loading="true" :src="userInfo.avatar" radius= 10 width="80px" height="80px"></up-image>
			
			<view class="info">
				<span>{{userInfo.nickname}}</span>
				<span>{{userInfo.mobile}}</span>
				<span v-if="userInfo.level">{{userInfo.level.name}}</span>
			</view>
		</view>
		<view class="">
			<view class="remark">
				<span style="">备注</span>
				<up-textarea v-model="formData.remark" placeholder="请输入内容" count ></up-textarea>
			</view>
			<up-button type="primary" text="申请添加养护人" @tap="onAddConserveHandler"></up-button>
		</view> -->
	
	
</template>

<style lang="scss" scoped>
	.user{
		background-color: #fff;
		margin: 10rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-radius: 16rpx;
		
		.info{
			width: 100%;
			display: flex;
			flex-direction: column;
			justify-content: start;
	
			border: red 1rpx solid;
		}
	}
	.remark{
		
	}
</style>
